/**
 * @projectName: pet-joy-home
 * @author: 小飞
 * @description: TODO
 * @date: 2024/8/13 17:29
 * @version: 1.0
 */
package com.home.config.commonConfig;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.home.constant.MessageConstant;
import com.home.utils.SecurityContextUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, MessageConstant.SET_CREATE_USER, Long.class, null != SecurityContextUtil.getLoginUser()?SecurityContextUtil.getLoginUser().getUser().getId():null);
        this.strictInsertFill(metaObject,MessageConstant.SET_CREATE_TIME, Date.class,new Date());
        this.strictInsertFill(metaObject,MessageConstant.Set_UPDATE_USER,Long.class,null != SecurityContextUtil.getLoginUser()?SecurityContextUtil.getLoginUser().getUser().getId():null);
        this.strictInsertFill(metaObject,MessageConstant.SET_UPDATE_TIME, Date.class,new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,MessageConstant.Set_UPDATE_USER,Long.class,null != SecurityContextUtil.getLoginUser()?SecurityContextUtil.getLoginUser().getUser().getId():null);
        this.strictUpdateFill(metaObject,MessageConstant.SET_UPDATE_TIME, Date.class,new Date());
    }
}
